#include <iostream>
#include <vector>

using namespace std;

class Solution 
{
public:
	vector<int> sortArrayByParityII(vector<int>& nums) 
	{
		vector<int> v(nums.size());
		int j = 1, o = 0;
		for (int i = 0; i < nums.size(); i++)
		{
			if (nums[i] % 2 == 0)
			{
				v[o] = nums[i];
				o += 2;
			}
			else
			{
				v[j ] = nums[i];
				j += 2;
			}
		}

		return v;
	}
};
int main()
{
	vector<int> nums{ 4,2,5,7 };

	Solution xz;
	vector<int> v = xz.sortArrayByParityII(nums);
	for (auto e : v)
	{
		cout << e << " ";
	}

	return 0;
}
